package com.lwy.qiuchao.vending.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.lwy.qiuchao.vending.vo.FieldVo;
import com.lwy.qiuchao.vending.vo.VendingDetailVo;
import com.lwy.qiuchao.vending.vo.VendingNumVo;
import com.lwy.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lwy.qiuchao.vending.entity.VendingMachineEntity;
import com.lwy.qiuchao.vending.service.VendingMachineService;
import com.lwy.common.utils.PageUtils;


/**
 * 
 *
 * @author lwy
 * @email ${email}
 * @date 2020-12-01 15:51:09
 */
@RestController
@RequestMapping("vending/vendingmachine")
public class VendingMachineController {
    @Autowired
    private VendingMachineService vendingMachineService;

    @RequestMapping("/select")
    public R selectFieldandVend(){
       List<FieldVo> vos = vendingMachineService.selectFieldandVend();
       return R.ok().put("data",vos);
    }
    /**
     * 通过所有球场id查询每个球场所有的贩卖机数
     * */
    @RequestMapping("/listnum")
    public R listFieldandvnum(@RequestParam Map<String, Object> params){
        List<VendingNumVo> vos = vendingMachineService.listFieldandvnum(params);
        return R.ok().put("data",vos);
    }

    /**
     * 通过指定球场id查询每个球场所有贩卖机的详细信息
     * */
    @RequestMapping("/detail/{field}")
    public R vendingDetailbyFieldid(@PathVariable("field") Long field){
       List<VendingDetailVo> vos = vendingMachineService.vendingDetailbyFieldid(field);
        return R.ok().put("data",vos);
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = vendingMachineService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{vendId}")
    public R info(@PathVariable("vendId") Long vendId){
		VendingMachineEntity vendingMachine = vendingMachineService.getById(vendId);

        return R.ok().put("vendingMachine", vendingMachine);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody VendingMachineEntity vendingMachine){
		vendingMachineService.save(vendingMachine);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody VendingMachineEntity vendingMachine){
        System.out.println(vendingMachine);
        vendingMachineService.updateStatus(vendingMachine);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody VendingMachineEntity vendingMachine){
		vendingMachineService.removeOne(vendingMachine);

        return R.ok();
    }

}
